<template>
  <view class="custom-nav-bar" :style="{marginTop: `${marginTopVal}rpx;`, width: `${barWidth}`} ">
    <view class="left iconfont icon-btn-back" @click="navigateBack"/>
    <view class="title">{{ title }}</view>
    <view class="right" @click="onRightClick">{{ rightText }}</view>
  </view>
</template>
<script setup>
import {defineProps, getCurrentInstance, onMounted, ref} from 'vue'
import {px2Rpx, wxGetCapsulePosition, wxGetTopHeight} from "@/utils/utils";

const {proxy} = getCurrentInstance()
const props = defineProps({
  title: String,
  rightText: String,
  backRoutePath: String,
})

const marginTopVal = ref(0)
const barWidth = ref('null')

const navigateBack = () => {
  uni.switchTab({
    url: props.backRoutePath
  })
}

const onRightClick = () => {
  proxy.$emit('rightClick', props.rightText)
}

const setStatusTopInstance = () => {
  const {left} = wxGetCapsulePosition()
  barWidth.value = `${px2Rpx(left) - 80}rpx`
  marginTopVal.value = wxGetTopHeight()
}

onMounted(() => {
  /*  #ifdef MP-WEIXIN */
  setStatusTopInstance()
  /* #endif */
})

</script>


<style scoped lang=less>
.custom-nav-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 40rpx;
  color: #000;
  font-family: "ali-m";;
  background-color: #f8f8f8;
  height: 5vh;
}
</style>
